home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / comm / txtq130.zip / HEAPMAN.PAS < prev    next >
Pascal/Delphi Source File  |  1996-01-26  |  2KB  |  86 lines

  1. (*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2.  
  3.              Heap management procedures, by Keld R. Hansen
  4.                     From SWAG, in the "EXEC" section
  5.  
  6.  
  7. EXECUTE shrinks your program's memory allocation to the smallest possible
  8. value, runs the specified program, and then expands the memory allocation
  9. again.  Works in TP 6.0 and 7.0!
  10. ________________________________________________________________________*)
  11.  
  12. {$N-,E- no math support needed}
  13. {$X- function calls may not be discarded}
  14. {$I- disable I/O checking (trap errors by checking IOResult)}
  15. {$S- no stack checking code [routine will fail without this directive!]}
  16.  
  17. Unit HeapMan;
  18.  
  19. Interface
  20.  
  21. USES
  22.   DOS;
  23.  
  24. PROCEDURE ReallocateMemory(P : POINTER);
  25. FUNCTION EXECUTE(Name : PathStr ; Tail : STRING) : WORD;
  26.  
  27. Implementation
  28.  
  29. PROCEDURE ReallocateMemory(P : POINTER); ASSEMBLER;
  30. ASM
  31.   MOV  AX, PrefixSeg
  32.   MOV  ES, AX
  33.   MOV  BX, WORD PTR P+2
  34.   CMP  WORD PTR P,0
  35.   JE   @OK
  36.   INC  BX
  37.  
  38.  @OK:
  39.   SUB  BX, AX
  40.   MOV  AH, 4Ah
  41.   INT  21h
  42.   JC   @X
  43.   LES  DI, P
  44.   MOV  WORD PTR HeapEnd,DI
  45.   MOV  WORD PTR HeapEnd+2,ES
  46.  
  47.  @X:
  48. END;
  49.  
  50. FUNCTION EXECUTE(Name : PathStr ; Tail : STRING) : WORD; ASSEMBLER;
  51. ASM
  52. {$IFDEF CPU386}
  53.   DB      66h
  54.   PUSH    WORD PTR HeapEnd
  55.   DB      66h
  56.   PUSH    WORD PTR Name
  57.   DB      66h
  58.   PUSH    WORD PTR Tail
  59.   DB      66h
  60.   PUSH    WORD PTR HeapPtr
  61. {$ELSE}
  62.   PUSH    WORD PTR HeapEnd+2
  63.   PUSH    WORD PTR HeapEnd
  64.   PUSH    WORD PTR Name+2
  65.   PUSH    WORD PTR Name
  66.   PUSH    WORD PTR Tail+2
  67.   PUSH    WORD PTR Tail
  68.   PUSH    WORD PTR HeapPtr+2
  69.   PUSH    WORD PTR HeapPtr
  70. {$ENDIF}
  71.   CALL ReallocateMemory
  72.   CALL SwapVectors
  73.   CALL DOS.EXEC
  74.   CALL SwapVectors
  75.   CALL ReallocateMemory
  76.   MOV  AX, DosError
  77.   OR   AX, AX
  78.   JNZ  @OUT
  79.   MOV  AH, 4Dh
  80.   INT  21h
  81.  
  82.  @OUT:
  83. END;
  84.  
  85. End.
  86.